﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="OAuthTokenExplorerWeb.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>OAuth Object Explorer</title>
    <script src="../Scripts/jquery-1.9.1.min.js"></script>
    <link href="Style.css" rel="stylesheet" />
    <script>
        var hostweburl;

        // Load the SharePoint resources.
        $(document).ready(function () {

            // Get the URI decoded app web URL.

            hostweburl =
                decodeURIComponent(
                    getQueryStringParameter("SPHostUrl")
            );


            // The SharePoint js files URL are in the form:
            // web_url/_layouts/15/resource.js
            var scriptbase = hostweburl + "/_layouts/15/";

            // Load the js file and continue to the 
            // success handler.
            $.getScript(scriptbase + "SP.UI.Controls.js", renderChrome)
        });



        //Function to prepare the options and render the control
        function renderChrome() {
            // The Help, Account and Contact pages receive the 
            //   same query string parameters as the main page
            var options = {"appTitle": "OAuth Token Explorer",
                            "settingsLinks": [
                        {
                            "linkUrl": "https://www.arthurgraus.nl",
                            "displayName": "Contact me"
                        }
                    ]
                };

            var nav = new SP.UI.Controls.Navigation("chrome_ctrl_container", options);
            nav.setVisible(true);
        }



        // Function to retrieve a query string value.
        // For production purposes you may want to use
        // a library to handle the query string.
        function getQueryStringParameter(paramToRetrieve) {
            try {
                var params =
                    document.URL.split("?")[1].split("&");
                var strParams = "";
                for (var i = 0; i < params.length; i = i + 1) {
                    var singleParam = params[i].split("=");
                    if (singleParam[0] == paramToRetrieve)
                        return singleParam[1];
                }
            }
            catch (err)
            { return ""; }
        }
    </script>

    
</head>
<body>
    <form id="form1" runat="server">
    
        
        <div id="chrome_ctrl_container" ></div>

        <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>

        <div id="main">
            <h1>SharePoint Context</h1>

            <h2>HostWeb</h2>
            <p>
                <asp:Literal ID="litHostWeb" runat="server" Text=""></asp:Literal>
            </p>

            <h2>User</h2>
            <p>
                <asp:Literal ID="litUser" runat="server"></asp:Literal>
            </p>

            <h1>App Context</h1>

            <h2>ClientId == AppId</h2>
            <p>
                <asp:Literal ID="litClientId" runat="server" Text=""></asp:Literal>
            </p>
            <p>
                &nbsp;</p>

            <h1>OAuth Tokens</h1>

            <h2>ContextToken value (spAppToken) Base 64 encoded</h2>
            <asp:Literal ID="litContextTokenValue" runat="server"></asp:Literal>


            <h2>ContextToken contents (JWT = Json Web Token)</h2>
            <asp:Literal ID="litContextToken" runat="server"></asp:Literal>

            <br />

            <h2>AccessToken value</h2>
            <asp:Literal ID="litAccessTokenValue" runat="server"></asp:Literal>


            <h2>AccessToken contents (JWT =  Json Web Token)</h2>
            <asp:Literal ID="litAccessToken" runat="server"></asp:Literal>


            <h2>AccessToken (AppOnly) value</h2>
            <asp:Literal ID="litAccessTokenValueAppOnly" runat="server"></asp:Literal>


            <h2>AccessToken (AppOnly) contents (JWT =  Json Web Token)</h2>
            <asp:Literal ID="litAccessTokenAppOnly" runat="server"></asp:Literal>

            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </div>


    </form>
</body>
</html>
